package org.henau.EmergencyHandlerChain;

// 3. 责任链处理器抽象类 (EmergencyHandler.java)
public abstract class EmergencyHandler {
    protected EmergencyHandler nextHandler;

    public void setNextHandler(EmergencyHandler next) {
        this.nextHandler = next;
    }

    public void handleEvent(EmergencyEvent event) {
        if (canHandle(event)) {
            processEvent(event);
        } else if (nextHandler != null) {
            nextHandler.handleEvent(event);
        } else {
            handleUnresolved(event);
        }
    }

    protected abstract boolean canHandle(EmergencyEvent event);
    protected abstract void processEvent(EmergencyEvent event);

    protected void handleUnresolved(EmergencyEvent event) {
        System.out.println("[默认处理] 事件未处理: " + event);
        event.setResolved(false);
    }
}